#!/bin/bash -e
# Running from a git repo
# Assumes iiab repos are downloaded

apt -y update
apt -y full-upgrade

apt -y install git curl nano gawk wget pastebinit

cd /opt/iiab/iiab
scripts/ansible

# 2022-09-27: iiab-install now handles this
#mkdir -p /etc/iiab/install-flags

if [ ! -f /etc/iiab/local_vars.yml ]; then
  cp /opt/iiab/iiab/vars/local_vars_none.yml /etc/iiab/local_vars.yml
fi
# Fix up swap
PI_SWAP_FILE_SIZE=1536
if [ -f /etc/rpi/swap.conf ] && [ ! -f /etc/rpi/swap.conf.d/90-iiab-swap.conf ]; then
    mkdir -p /etc/rpi/swap.conf.d/
    cat << EOF > /etc/rpi/swap.conf.d/90-iiab-swap.conf
[Main]
Mechanism=swapfile

[File]
FixedSizeMiB=$PI_SWAP_FILE_SIZE
EOF
fi

reboot
